﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kaskelot.SP.Core
{
	public static class BoolExtensions
	{
		public static string Ja { get { return "Ja"; } }
		public static string Nej { get { return "Nej"; } }
		public static string Aktiv { get { return "Aktiv"; } }
		public static string Inaktiv { get { return "Inaktiv"; } }
		public static string Klar { get { return "Klar"; } }
		public static string EjKlar { get { return "Ej klar"; } }

		public static string ToKlarEjKlar(this bool from)
		{
			return from ? Klar : EjKlar;
		}

		public static bool FromKlarEjKlar(this string from)
		{
			if (from == Klar)
				return true;
			else if (from == EjKlar)
				return false;
			else
				throw new ArgumentException("Parameter is neither 'Klar' nor 'Ej klar'");
		}

		public static string ToJaNej(this bool from)
		{
			return from ? Ja : Nej;
		}

		public static string ToJaNej(this bool? from, string def)
		{
			if (!from.HasValue)
				return def;
			else
				return from.Value.ToJaNej();
		}

		public static bool FromJaNej(this string from)
		{
			if (from == Ja)
				return true;
			else if (from == Nej)
				return false;
			else
				throw new ArgumentException("Parameter is neither 'Ja' nor 'Nej'");
		}

		public static string ToAktivInaktiv(this bool from)
		{
			return from ? Aktiv : Inaktiv;
		}

		public static string ToAktivInaktiv(this bool? from, string def)
		{
			if (!from.HasValue)
				return def;
			else
				return from.Value.ToAktivInaktiv();
		}

		public static bool FromAktivInaktiv(this string from)
		{
			if (from == Aktiv)
				return true;
			else if (from == Inaktiv)
				return false;
			else
				throw new ArgumentException("Parameter is neither 'Aktiv' nor 'Inaktiv'");
		}
	}
}